import { useSelector, useDispatch } from 'react-redux'
import { updateName, updateAge } from './store/actions'

export default function User() {
  const {
    user: { name, age },
  } = useSelector((state) => state)
  const dispatch = useDispatch()
  return (
    <div>
      <h2>
        name: {name} age: {age}
      </h2>
      {/* <button onClick={() => dispatch({ type: 'UPDATE_NAME', payload: 'xxx' })}>
        更改 name
      </button> */}
      <button onClick={() => dispatch(updateName('xxx'))}>更改 name</button>
      <button onClick={() => dispatch(updateAge(2))}>更改 age</button>
    </div>
  )
}
